import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'package:flutter_rider/api/api.dart';
import 'package:flutter_rider/module/task/page/task_detail_page.dart';
import 'package:flutter_rider/module/waybill/page/confirm_order_page.dart';
import 'package:flutter_rider/module/waybill/page/waybill_change.dart';
import 'package:flutter_rider/module/waybill/page/waybill_detail_page.dart';
import 'package:flutter_rider/routers/fluro_navigator.dart';
import 'package:flutter_rider/routers/i_router.dart';
import 'package:flutter_rider/utils/tip.dart';

class WaybillRouter implements IRouterProvider {
  static String waybillPage = '/waybill';
  static String waybillDetailPage = '/waybill/detail';
  static String confirmOrderPage = '/waybill/confirmOrder';
  static String waybillChangePage = '/waybill/detail/change';


  

  @override
  void initRouter(FluroRouter router) {
    router.define(waybillDetailPage,
        handler: Handler(handlerFunc: (context, params) {
      /// 类参数
      final id = context?.settings?.arguments as String;
      return WaybillDetailPage(id);
    }));

    router.define(confirmOrderPage,
        handler: Handler(handlerFunc: (context, params) {
      /// 类参数
      final data = context?.settings?.arguments;
      return ConfirmOrderPage(data);
    }));

    router.define(waybillChangePage,
        handler: Handler(handlerFunc: (context, params) {
      /// 类参数
      final data = context?.settings?.arguments;
      return WaybillChangePage(data);
    }));

    
  }

  static openWaybillDetail(BuildContext context, String id){

    Api.getx(context, "/waybill/detail?waybill_no=$id",
        progress: false, success: (data) {
        var st = data["status"];
      if (st == 1) {
        var _sp = Api.getSp();
        bool _showCompleteWaybillOrder =
            _sp.getBool("_showCompleteWaybillOrder") as bool;
        if (_showCompleteWaybillOrder) {
          NavigatorUtils.push(context, WaybillRouter.confirmOrderPage,
              arguments: data);
        } else {
          Tip.show("当前没有“完善运单”的权限，无法操作");
        }
        
      } else {
        NavigatorUtils.push(context, WaybillRouter.waybillDetailPage,
            arguments: data["waybill_no"]);
      }
    }, failTip: "运单未确认，暂时无法装货", fail: (_) {});
  }

}
